package com.controller;

import com.pojo.SysUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;


/**
 * 第一个Spring MVC控制器
 */
@Controller
public class HelloController{
    /**
     * hello Spring MVC
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/index")
    public ModelAndView Hello(@RequestParam /**(required = false)*/ String realName) throws Exception{
        System.out.println("你好！"+realName+"欢迎来到Spring MVC课堂。");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("realName",realName);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    @RequestMapping("/index2")
    public String index2(Model model, @RequestParam String realName) throws Exception{
        System.out.println("你好！"+realName+"欢迎来到Spring MVC课堂。");
        model.addAttribute("realName",realName);
        model.addAttribute(realName);
        SysUser sysUser = new SysUser();
        sysUser.setRealName(realName);
        model.addAttribute("currentUser",sysUser);
        model.addAttribute(sysUser);
        return "index";
    }

    @RequestMapping("/index3")
    public String index3(Map<String,Object> map,@RequestParam String realName) throws Exception{
        System.out.println("你好！"+realName+"欢迎来到Spring MVC课堂。");
        map.put("realName",realName);
        return "index";
    }
}
